<template>
  <div>
    <van-nav-bar    fixed=true  placeholder=true title="我已出租的" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-card v-for="(detailItem, index) in tableData" :key="index" :price="detailItem.price" :title="detailItem.title"
              :desc="detailItem.description" :thumb="detailItem.url" @click="toDetails(detailItem.id)">
    </van-card>
    <van-button v-if="showB" type="primary" @click="expand">更多订单</van-button>
    <div style="height:200px"></div>
  </div>
</template>
<script>
let number = 0
export default {
  name: 'ProductPage',
  data() {
    return {
      showB:false,
      tableData: [],
      totalData: [],
    };
  },
  created() {
    this.init()
  },
  components: {
  },
  methods: {
    init() {
       number = 4
      this.axios({
        method: "GET",
        url: "/aapi/rented"
      }).then(response => {
        this.totalData = response.data
        this.tableData = response.data.slice(0, number)
        if (this.tableData == undefined || this.tableData.length <= 0){
              this.showB = false
        }else {
              this.showB = true
        }
        if(this.tableData.length == this.totalData.length ){
            this.showB = false
        }
      })
    },
    onClickLeft() {
      this.$router.push('/gerenzhuye')
    },
    expand() {
     number = number + 4
      this.tableData = this.totalData.slice(0, number)
    },
    toDetails(id) {
      this.$store.commit("deliverId", id)
      this.$router.push('/delivery')
    },
  }
}
</script>
